package com.technology.education.ui.common.withdraw_record

import androidx.core.os.bundleOf
import com.angcyo.dsladapter.dpi
import com.angcyo.dsladapter.dslItem
import com.angcyo.dsladapter.toDslItemList
import com.technology.education.R
import com.technology.education.base.BaseRecyclerTopBarFragment
import com.technology.education.data.AppData
import com.technology.education.data.model.WithdrawOrder
import com.technology.education.ext.navigation
import com.technology.education.ext.setPageItems
import me.hgj.jetpackmvvm.ext.parseState

/**
 * 提现记录
 */
class WithdrawRecordFragment : BaseRecyclerTopBarFragment<WithdrawRecordViewModel>() {
    override fun initViews() {
        setTitle("提现记录")
    }

    override fun lazyLoadData() {
        loading()
    }

    private fun setUI(list: List<WithdrawOrder>) {
        renderAdapter {
            setPageItems(list.toDslItemList(R.layout.item_withdraw_record) {
                itemBindOverride = { itemHolder, _, _, _ ->
                    itemBottomInsert = 8 * dpi
                    itemData?.let {
                        if (it is WithdrawOrder) {
                            itemHolder.tv(R.id.tv_money)?.text = it.titleStr
                            itemHolder.tv(R.id.tv_status)?.text = it.statusStr
                            itemHolder.tv(R.id.tv_date)?.text = it.createDate
                            itemHolder.clickItem { view ->
                                navigation(
                                    view,
                                    R.id.action_withdraw_record_to_detail,
                                    bundleOf("id" to it.id,"type" to if (AppData.MEMBER_TYPE=="2") 3 else 1)
                                )
                            }
                        }
                    }

                }
            }, mViewModel.pageIndex)
        }
    }

    override fun createObserver() {
        mViewModel.result.observe(this) {
            parseState(it, onSuccess = { data ->
                setUI(data.list)
            })
        }
    }
}